package com.seo.utils;


import org.apache.commons.lang3.StringUtils;
import org.xbill.DNS.Cache;
import org.xbill.DNS.Lookup;
import org.xbill.DNS.Record;
import org.xbill.DNS.Resolver;
import org.xbill.DNS.SimpleResolver;
import org.xbill.DNS.Type;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DomainUtil {

	public static boolean checkTxt(String domain, String txt) {
		try {
			Resolver resolver = new SimpleResolver("114.114.114.114");
			Lookup lookup = new Lookup(domain, Type.TXT);
			lookup.setResolver(resolver);
			Cache cache = new Cache();
			lookup.setCache(cache);
			lookup.run();
			if (lookup.getResult() == Lookup.SUCCESSFUL) {
				Record[] records = lookup.getAnswers();
				for (Record record : records) {
					String res = record.rdataToString();
					log.info("对比内容-[{}]-[{}]", res, txt);
					if (StringUtils.contains(res, txt)) {
						return true;
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	public static boolean checkCname(String domain, String cname) {
		try {
			Resolver resolver = new SimpleResolver("114.114.114.114");
			Lookup lookup = new Lookup(domain, Type.CNAME);
			lookup.setResolver(resolver);
			Cache cache = new Cache();
			lookup.setCache(cache);
			lookup.run();
			if (lookup.getResult() == Lookup.SUCCESSFUL) {
				Record[] records = lookup.getAnswers();
				for (Record record : records) {
					String res = record.rdataToString();
					log.info("对比内容-[{}]-[{}]", res, cname);
					if (StringUtils.contains(res, cname)) {
						return true;
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	public static void main(String args[]) {
		//System.out.println(checkTxt("verify.3dianwl.com","c7a154201cfc7efccec8b0324f9e1ad7"));
		System.out.println("2019-12-03 09:29:44".replaceAll("-", "/"));
	}
}
